﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Speedy
{
    public partial class frmSeriDegistir : XtraForm
    {
        public int RecId { get; set; }


        private string Change()
        {
            try
            {
                string sql = string.Format("update  INVOICE_HEADER set  INVOICE_SERIES= '{0}', INVOICE_NUMBER={1},DESCRIPTION='' where ID ={2}", txtSeri.Text, txtSira.Text, RecId.ToString());
                DataLayer.GetLayer.ExecQuery(sql);
                return "";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }


        public frmSeriDegistir()
        {
            InitializeComponent();
            txtSira.GotFocus += new EventHandler(txtSira_GotFocus);
        }

        void txtSira_GotFocus(object sender, EventArgs e)
        {
            txtSira.Text = DataLayer.GetLayer.ExecScalar(string.Format("SELECT     ISNULL(MAX(INVOICE_NUMBER), 0) + 1 AS sira FROM         INVOICE_HEADER  WHERE     (INVOICE_SERIES = N'{0}')", txtSeri.Text)).ToString();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            string sonuc = Change();
            if (sonuc == "")
            {
                MessageBox.Show("Evrak Seri Ve Sıra Değiştirilmiştir !");
                DialogResult = DialogResult.OK;
                this.Close();
            }
            else
                MessageBox.Show("Hata Oluştu \r\n" + sonuc);
        }
    }
}
